﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace TST.SharePointObjects
{
    internal class SharePointGroupList : SiteObjectList
    {
        public SharePointGroupList(LicensingMode licensingMode, SPSite site, SPWeb web, Guid farmID, SharePointObjectsDatabase database)
            : base(licensingMode, site, web, farmID, database)
        {
        }

        protected override void doLoadFromWeb()
        {
            foreach (SPGroup group in Web.SiteGroups)
            {
                SiteObject obj = new SiteObject(group.ID.ToString(), group.Name, SiteObjectType.SharePointGroup);
                Add(obj);
            }
        }

        protected override void doLoadFromWeb(string groupFilter, string nameSearch)
        {
            foreach (SPGroup group in Web.SiteGroups)
            {
                if (string.IsNullOrEmpty(nameSearch) || group.Name.ToLower().Contains(nameSearch.ToLower()))
                {
                    SiteObject obj = new SiteObject(group.ID.ToString(), group.Name, SiteObjectType.SharePointGroup);
                    obj.Url = string.Format("{0}/_layouts/editgrp.aspx?Group={1}", Web.Url, System.Web.HttpUtility.UrlEncode(group.Name));
                    Add(obj);
                }
            }
        }

        public override SiteObjectType SiteObjectType
        {
            get
            {
                return SiteObjectType.SharePointGroup;
            }
        }

    }
}
